<?php
$ROOT_DIR_PATH = '../';
require_once($ROOT_DIR_PATH . 'includes/includes.php');
require_once($ROOT_DIR_PATH . 'classes/class.banner.inc.php');
require_once($ROOT_DIR_PATH . 'classes/class.category.inc.php');require_once($ROOT_DIR_PATH . 'classes/class.brand_cateogry.inc.php');
require_once($ROOT_DIR_PATH . 'classes/class.product.inc.php');
require_once($ROOT_DIR_PATH . 'classes/class.productgallery.inc.php');
require_once($ROOT_DIR_PATH . 'classes/class.brand.inc.php');require_once($ROOT_DIR_PATH . 'classes/class.emailtemplate.inc.php');
$bannerObj = new banner();
$categoryObj = new category();
$productObj = new product();
$brandObj = new brand();
$productgalleryObj = new productgallery();
$brandCategory = new brand_category();
$emailtemplateObj = new emailtemplate();
if (!$GENOBJ->isLoggedIn()) {
    exit;
}
if (isset($_POST)) {
    $CALLBACK_FUNCTION = '';
    $ARGUMENT = array();
    if (isset($_POST['callback'])) {
	$CALLBACK_FUNCTION = $_POST['callback'];
	$filterArray = Array("TrimElement", "mysqlRealEscape");
	$CALLBACK_FUNCTION = $GENOBJ->filter($CALLBACK_FUNCTION, $filterArray);
		if ($CALLBACK_FUNCTION == 'categoryDelete') {
            $categoryid = isset($_POST['categoryid']) ? $_POST['categoryid'] : '';
            $categoryid = $GENOBJ->filter($categoryid, $filterArray);
            $dataArray['categoryid'] = $categoryid;
            $result = $categoryObj->categoryDelete($dataArray);
			echo $result; exit;	
		} elseif ($CALLBACK_FUNCTION == 'brandDelete') {
			$brandid = isset($_POST['brandid']) ? $_POST['brandid'] : '';
            $brandid = $GENOBJ->filter($brandid, $filterArray);
            $dataArray['brandid'] = $brandid;
            $result = $brandObj->brandDelete($dataArray);
			echo $result; exit;		} elseif ($CALLBACK_FUNCTION == 'emailTemplateImageDelete') {			$templateid = isset($_POST['templateid']) ? $_POST['templateid'] : '';			$templateid = $GENOBJ->filter($templateid, $filterArray);			$filename = isset($_POST['filename']) ? $_POST['filename'] : '';			$filename = $GENOBJ->filter($filename, $filterArray);			$emailtemplateObj->updateImage($templateid, '');			$sourceFolder = '../upload/images/emailtemplate/';			$imagepath = $sourceFolder . trim($filename);			if (file_exists($imagepath)) {				@unlink($imagepath);			}		} else if ($CALLBACK_FUNCTION == 'newsletterImageDisplay') {			$templateid = isset($_POST['templateid']) ? $_POST['templateid'] : '';			$templateid = $GENOBJ->filter($templateid, $filterArray);			$templateArray = $emailtemplateObj->select($templateid);			if (count($templateArray) > 0) {				echo $templateArray['image'];				exit;			} else {				echo 'noimg.jpg';				exit;			}				} else if ($CALLBACK_FUNCTION == 'bannerImageDelete') {
			$bannerid = isset($_POST['bannerid']) ? $_POST['bannerid'] : '';
			$bannerid = $GENOBJ->filter($bannerid, $filterArray);
			$filename = isset($_POST['filename']) ? $_POST['filename'] : '';
			$filename = $GENOBJ->filter($filename, $filterArray);
			$bannerObj->updateImage($bannerid, '');
			$sourceFolder = '../upload/images/banner/';
			$imagepath = $sourceFolder . trim($filename);
			$thumb_imagepath = $sourceFolder . trim("thumb_" . $filename);
			if (file_exists($imagepath)) {
				@unlink($imagepath);
			}
			if (file_exists($thumb_imagepath)) {
				@unlink($thumb_imagepath);
			}
		} else if ($CALLBACK_FUNCTION == 'productDefaultImageDelete') {
			$productid = isset($_POST['productid']) ? $_POST['productid'] : '';
			$productid = $GENOBJ->filter($productid, $filterArray);
			$filename = isset($_POST['filename']) ? $_POST['filename'] : '';
			$filename = $GENOBJ->filter($filename, $filterArray);
			$productObj->updateImage($productid, '');
			$productObj->deleteImagename($filename);
		} else if ($CALLBACK_FUNCTION == 'productGalleryImageDelete') {
			$id = isset($_POST['id']) ? $_POST['id'] : '';
			$id = $GENOBJ->filter($id, $filterArray);
			$filename = isset($_POST['filename']) ? $_POST['filename'] : '';
			$filename = $GENOBJ->filter($filename, $filterArray);
			$productgalleryObj->delete($id);
			$productgalleryObj->deleteImage($filename);						} else if ($CALLBACK_FUNCTION == 'brandHomeImageDelete') {			$brandId = isset($_POST['brandid']) ? $_POST['brandid'] : '';			$brandId = $GENOBJ->filter($brandId, $filterArray);			$filename = isset($_POST['filename']) ? $_POST['filename'] : '';			$filename = $GENOBJ->filter($filename, $filterArray);			$brandObj->updateHomeImage($brandId, '');			$brandObj->deleteHomeImage($filename);		
		} else if ($CALLBACK_FUNCTION == 'brandImageDelete') {
			$brandId = isset($_POST['brandid']) ? $_POST['brandid'] : '';
			$brandId = $GENOBJ->filter($brandId, $filterArray);
			$filename = isset($_POST['filename']) ? $_POST['filename'] : '';
			$filename = $GENOBJ->filter($filename, $filterArray);
			$brandObj->updateImage($brandId, '');
			$brandObj->deleteImage($filename);
		} else if ($CALLBACK_FUNCTION == 'categoryGenerate') {			//This function is used to add the category list box in the brand page			$categoryString = '';			$categoryArray = $categoryObj->getAllCategoryList('id,title,parentid', "where status = '1'");						$categoryString .= '<div class="pageoverflow upload-category-container">							<div class="pagetext">Category<span class="error-star">*</span>:</div>							<div class="pageinput">								<select name="cid[]">								    <option value="">--Select Category--</option>';									foreach($categoryArray as $key => $value) {									$categoryString .= "<option value='".$value['id']."'>".$value['title']."</option>";									}								$categoryString .= '</select>								<input type="button" name="Add Category" value="Add category" class="add_category"/>								<input type="button" name="Remove Category" value="Remove Category" relation_id="" class="remove_category"/>							</div>						</div>';			echo $categoryString;			exit;		} else if ($CALLBACK_FUNCTION == 'showCategoryBybrand') {			//This function is used to add the category list box content in the product page			$brandId = isset($_POST['brandid']) ? $_POST['brandid'] : '';			$brandId = $GENOBJ->filter($brandId, $filterArray);						$categoryId = isset($_POST['categoryid']) ? $_POST['categoryid'] : '';			$categoryId = $GENOBJ->filter($categoryId, $filterArray);						$categoryString = '';			$categoryArray = $brandCategory->getCategoryBybrand($brandId);			$categoryString = '<option value="">--Select Category--</option>';			if ($categoryArray) {				foreach( $categoryArray as $_category ) {					$selected = ($categoryId == $_category['cid'])?"selected":"";					$categoryString .= "<option value='".$_category['cid']."' ".$selected." >".$_category['title']."</option>";				}			}			echo $categoryString; 			exit;		} else if ($CALLBACK_FUNCTION == 'brand_category_delete') {		//This function is used to add the category list box content in the product page			$relation_id = isset($_POST['relation_id']) ? $_POST['relation_id'] : '';			$relation_id = $GENOBJ->filter($relation_id, $filterArray);			$brandCategory->delete($relation_id);		}						
    }
    exit;
}
exit;
?>